package com.bjqh.edu.Base;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import com.bjqh.edu.R;
import com.bjqh.edu.callback.ResultListener;

import java.util.List;


/**
 * Created by Administrator on 2016/12/7.
 */

public abstract class EasyActivity extends AppCompatActivity {

    private ProgressDialog dialog;



    /** 初始化视图 **/
    protected abstract void initViews();

    /** 初始化事件 **/
    protected abstract void initData();

    /** 初始化事件 **/
    protected abstract void initEvents();
    /**加载list*/
    private AlertDialog mAlertDialog = null;
    /** 含有Bundle通过Class跳转界面 **/
    public void startActivity(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(this, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }
    /** 通过Class跳转界面 **/
    public void startActivity(Class<?> cls) {
        startActivity(cls, null);
    }


    public void eToast(String msg){
        Toast.makeText(EasyActivity.this,msg, Toast.LENGTH_SHORT).show();

    }
    public void showEAlertDialog(String title, String msg){
        Dialog alertDialog = new AlertDialog.Builder(this).
                setTitle(title).
                setMessage(msg).
                setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                }).create();
        alertDialog.show();
    }

    public void showEAlertDialog(String title, String msg,String buttonText, final ResultListener listener){
        Dialog alertDialog = new AlertDialog.Builder(this).
                setTitle(title).
                setMessage(msg).
                setPositiveButton(buttonText, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        listener.OnResultListener("");
                    }
                })
                .setNegativeButton("取消",null)
                .create();
        alertDialog.show();
    }



    public void showELoadingDialog(String msg){

        dialog = new ProgressDialog(this);
        dialog.setMessage(msg);
        dialog.show();

    }
    public  void removeEDialog(){
        if(dialog!=null&&dialog.isShowing()){
            dialog.dismiss();
        }
    }

    public void showListDialog(String title, List<String> list, AdapterView.OnItemClickListener mOnItemClickListener){
        View view =getLayoutInflater().inflate(R.layout.e_list_dialog, null);
        TextView dialog_generic_htv_title = (TextView) view.findViewById(R.id.dialog_generic_htv_title);
        dialog_generic_htv_title.setText(title);
        ListView news_list = (ListView) view.findViewById(R.id.news_list);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.e_list_dialog_item, R.id.tv_listItemTitle, list);
        news_list.setAdapter(adapter);
        news_list.setOnItemClickListener(mOnItemClickListener);
        mAlertDialog = new AlertDialog.Builder(this).create();
        mAlertDialog.show();
        mAlertDialog.getWindow().setContentView(view);

    }


    public  void removeEAlertDialog(){
        if(mAlertDialog!=null&&mAlertDialog.isShowing()){
            mAlertDialog.dismiss();
        }
    }

}
